今天先放code 明天再來解釋 還有些地方我看不懂
來源
https://github.com/victorfan336/WheelView
首先導入
implementation 'com.wx.wheelview:wheelview:1.3.3'
XML 設計
<com.wx.wheelview.widget.WheelView
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="@+id/whl">
</com.wx.wheelview.widget.WheelView>
自定義view
<TextView
android:id="@+id/item_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:gravity="center"
android:singleLine="true"
android:textSize="20sp" android:text="test"/>
自定義adapter
class MyWheelAdapter(private val mContext: Context) : BaseWheelAdapter() {
override fun bindView(position: Int, convertView: View?, parent: ViewGroup): View {
var convertView = convertView
val viewHolder: ViewHolder
if (convertView == null) {
viewHolder = ViewHolder()
convertView = LayoutInflater.from(mContext).inflate(R.layout.item_list, null)
viewHolder.textView = convertView!!.findViewById(R.id.item_name) as TextView
convertView.tag = viewHolder
} else {
viewHolder = convertView.tag as ViewHolder
}
viewHolder.textView!!.text = mList[position]
return convertView
}
internal class ViewHolder {
var textView: TextView? = null
}
}
Activity明天完成 我本來以為很簡單 結果弄了半天弄不出來 今天先寫一半